
//
// 101116 - AH - Created.
// 101119 - AH - Java doc. included. But with todos.
// 101128a- AH - HistoricalEvent when VisitorAction happens.
// 101128b- AH - Renamed from ResourceTableModel.
// 110702 - AH - (Garage) Deprecated this since used now deleted Rethor.
// 120321 - AH - Removed @Override for interface method (1.5 compatible).
//

package org.soekrat.gui.swing.chat;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import org.soekrat.AttributeObject;
import org.soekrat.engine.Soekrat2Engine;
import org.soekrat.engine.rethor.VisitorAction;

/**
 * <p>
 *   TODO
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
@SuppressWarnings("serial")
@Deprecated
public final class ResourceTalkTableModel extends AbstractTableModel 
{
  private final List<AttributeObject> m_resources=
    new ArrayList<AttributeObject>();
  
  private final Soekrat2Engine m_engine;
  
  private final List<Boolean> m_oks=new ArrayList<Boolean>();
  
  private final List<String> m_names=new ArrayList<String>();
  
  private final List<String> m_rethorOk=new ArrayList<String>();
  
  private final List<String> m_rethorHmm=new ArrayList<String>();
  
  /**
   * <p>
   * </p>
   * @param engine The engine the UI interfaces to.
   */
  public ResourceTalkTableModel(Soekrat2Engine engine)
  {
    if (engine==null)
    {
      throw new NullPointerException("engine");
    }
    
    m_engine=engine;
  }

  @Override
  public Class<?> getColumnClass(int col)
  {
    switch (col)
    {
      case 0 : return Boolean.class;
      case 1 : return String.class;
      case 2 : return String.class;  
      case 3 : return String.class;  
      default : throw new Error();
    }
  }

  @Override
  public String getColumnName(int col)
  {
    switch (col)
    {
      case 0 : return "Check?";
      case 1 : return "Name";
      case 2 : return "Ok";
      case 3 : return "Hmm";  
      default : throw new Error();
    }
  }

  // Declared in TableModel.
  public int getColumnCount(){ return 4; }

  // Declared in TableModel.
  public int getRowCount(){ return m_oks.size(); }  

  @Override
  public boolean isCellEditable(int row, int col) 
  {
    switch (col)
    {
      case 0 : return true;
      default : return false;
    }
  }

  // Declared in TableModel.
  public Object getValueAt(int row, int col) 
  {
    switch (col)
    {
      case 0 : return m_oks.get(row);
      case 1 : return m_names.get(row);
      case 2 : return m_rethorOk.get(row);
      case 3 : return m_rethorHmm.get(row);
      default : throw new Error();
    }
  }
  
  public void addResources(List<AttributeObject> resources)
  {
    m_names.clear();
    m_oks.clear();
    m_rethorHmm.clear();
    m_resources.clear();
    
    //Rethor rethor=m_engine.getRethor();
    
    if (resources!=null)
    {
      for (AttributeObject curr : resources)
      {
        m_resources.add(curr);
        
        String name=curr.getName();
        m_names.add(name);
        m_oks.add(Boolean.FALSE);
        m_rethorOk.add("");
        
        //String rethorReply=rethor.visitorFeedback(VisitorAction.HMMM, curr);
        //m_rethorHmm.add(rethorReply);
      }
    }
    
    fireTableDataChanged();
  }

  @Override
  public void setValueAt(Object val, int row, int col)
  {    
    if (col==0)
    {
      Boolean v=(Boolean)val;
      m_oks.set(row, v);
      
      AttributeObject resource=m_resources.get(row);
      
      VisitorAction va;
      if (v)
      {
        va=VisitorAction.OK;
        
        m_rethorHmm.set(row, "");
      }
      else
      {
        va=VisitorAction.HMMM;
        
        m_rethorOk.set(row, "");
      }
      
      fireTableRowsUpdated(row, row);
    }
  }
  
}
